<template>
  <div class="app-container">
    <form-filter @on-filter="submitFilterForm" :levelList="levelList"/>
    <el-table border :data="tableData.list" v-loading="loading" element-loading-text="加载中..." class="mgtop">
      <el-table-column label="时间"  prop="createTime" align="center" >
        <template slot-scope="{row}">
          {{row.createTime | toTime('YYYY-MM-DD HH:mm:ss')}}
        </template>
      </el-table-column>
      <el-table-column label="操作类型" prop="optType" align="center" >
        <template slot-scope="{row}">{{row.optType | switchOptType}}</template>
      </el-table-column>
      <el-table-column label="类型" prop="blackType" align="center">
        <template slot-scope="{row}">{{row.blackType | switchType}}</template>
      </el-table-column>
      <el-table-column label="值"  prop="blackTitle" align="center" >
      </el-table-column>
      <el-table-column label="调整前群组"  prop="oldLevelName" align="center" >
      </el-table-column>
      <el-table-column label="调整后群组"  prop="levelName" align="center" >
      </el-table-column>
      <el-table-column label="操作人"  prop="creator" align="center" >
      </el-table-column>
      <el-table-column label="备注" prop="remark" align="center">
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination background @size-change="gridSizeChange" @current-change="gridCurrentChange"
                     :current-page="filters.page" :page-sizes="gridPageSize" :page-size="filters.size"
                     :layout="gridLayout" :total="Number(tableData.total)">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import FormFilter from './levalFilter.vue';
import { grid } from '@/build';
import { blackListLog, risBlackListBehaviorLevelApi } from '@/services/api/risk';


export default {
  name: 'level-record',
  mixins: [grid],
  components: {
    FormFilter,
  },
  data() {
    return {
      // levelList: [],
      tableData: {
        list: [],
        total: 0,
      },
      filters: {
        page: 1,
        size: 20,
        optType: undefined, // 操作类型
        blackType: '', // 黑名单类型
        text: '', // 值
        creator: '', // 操作人
        level: [], // 群组
        oldLevel: [], // 调整前等级
        startDate: moment().format('YYYY-MM-DD 00:00:00'),
        endDate: moment().format('YYYY-MM-DD 23:59:59'),
      },
    };
  },
  filters: {
    switchOptType(optType) {
      let str = '';
      switch (optType) {
        case 0:
          str = '手动添加';
          break;
        case 1:
          str = '调整等级';
          break;
        case 2:
          str = '调整关联等级';
          break;
        default:
          break;
      }
      return str;
    },
    switchType(blackType) {
      return _.find(consts.BLACK_LIST_TYPE, { value: blackType.toString() }).label;
      // let type = '';
      // switch (blackType) {
      //   case 0:
      //     type = '账号';
      //     break;
      //   case 1:
      //     type = 'IP';
      //     break;
      //   case 2:
      //     type = '设备号';
      //     break;
      //   case 3:
      //     type = '银行卡';
      //     break;
      //   case 4:
      //     type = '手机号';
      //   case 5:
      //     type = '姓名';
      //     break;
      //   default:
      //     break;
      // }
      // return type;

    },
  },
  methods: {
    submitFilterForm(formInline) {
      const { time } = formInline;
      if (!_.isUndefined(time) && _.isArray(time)) {
        [this.filters.startDate, this.filters.endDate] = time;
        // formInline = { ...formInline, msg_start_time, msg_end_time };
      } else {
        this.filters.startDate = undefined;
        this.filters.endDate = undefined;
      }
      this.filters = { ...this.filters, ...formInline };
      this.filters.level = this.filters.level.join(',');
      this.filters.oldLevel = this.filters.oldLevel.join(',');
      this.doGet({ action: 'getGrid' });
    },
  },
  computed: {
    ...mapState({
      levelList: state => state.risk.levelList,
    }),

  },
  mounted() {
    // 获取等级下拉
    // this.bindGet(risBlackListBehaviorLevelApi, 'levelList', {
    //   action: 'getLevalList',
    //   format: (data) => {
    //     this.levelList = data;
    //     this.filters.level = [];
    //     this.filters.oldLevel = [];
    //     this.levelList.forEach((item) => {
    //       this.filters.level.push(item.levelId);
    //       this.filters.oldLevel.push(item.levelId);
    //     });
    //     this.filters.level = this.filters.level.join(',');
    //     this.filters.oldLevel = this.filters.oldLevel.join(',');
    //     this.doGet({ action: 'getGrid' });
    //     return data;
    //   },
    // });
    // this.getAll();
    this.bindGet(blackListLog, 'tableData', {
      action: 'getGrid',
      sendingData: 'filters',
    });
    this.filters.level = [];
    this.filters.oldLevel = [];
    this.levelList.forEach((item) => {
      this.filters.level.push(item.levelId);
      this.filters.oldLevel.push(item.levelId);
    });
    this.filters.level = this.filters.level.join(',');
    this.filters.oldLevel = this.filters.oldLevel.join(',');
    this.doGet({ action: 'getGrid' });


  },
};
</script>
<style lang="scss" scoped>
.mgtop{margin-top:30px}
</style>
